#include "head.h"

int main(int argc,char*argv[])
{

    // 初始化进程池
    proc_status_t list[3];
    initPool(list, 3);

    // 监听socket
    int socket_fd;
    initSocket(&socket_fd, "192.168.106.129", "8080");

    int epoll_fd = epoll_create(1);
    addEpoll(epoll_fd, socket_fd);

    while(1){

        struct epoll_event events[5];
        int epoll_num = epoll_wait(epoll_fd, events, 5, -1);

        for(int i=0; i<epoll_num; i++){
            struct epoll_event ev = events[i];

            if(ev.data.fd == socket_fd){
                // 有新链接到来
                int net_fd = accept(socket_fd, NULL, NULL);

                // 把net_fd交给子进程
                toSon(net_fd, list, 3);
            }
        }
    }
    
    close(socket_fd);
    return 0;
}

